<?php

namespace app\api\controller;

use think\Db;
use app\company\logic\Message;
use app\common\lib\SendIntegralNew;
use app\common\lib\EventCheck;

class Check extends Base
{
    //初审通过
    //公告.任务.积分奖扣.请假
    public function first_check_pass()
    {
        $id = I('id', 0);
        $type = I('type', 1); //1公告  2任务 3积分奖扣 4请假
        $first_check_opinion = I('first_check_opinion', '');
        if (empty($id)) {
            return return_json(1, 'id不能为空');
        }
        DB::startTrans();
        try {
            //发送消息
            $data_message = [];
            if ($type == 1) {//公告
                $users = M('com_notice')->where('id', $id)->find();
                if (!isset($users['status']) || $users['status'] != 0) {
                    return return_json(1, '状态不符合');
                }
                $data = [
                    'first_check_time' => time(),
                    'status' => 1,
                    'first_check_opinion' => $first_check_opinion
                ];
                $res = M('com_notice')->where('id', $id)->update($data);
                if (empty($res)) {
                    return return_json(1, '审核失败');
                }
                //记录人
                $data_message[] = [
                    'title' => '您有公告记录已通过初审',
                    'user_id' => $users['record_user_id'],
                    'cate_type' => 3,//公告消息
                    'type' => 1,//公告
                    'relation_id' => $id
                ];
                //终审人
                $data_message[] = [
                    'title' => '您有一条公告记录需要您审核(终审)',
                    'user_id' => $users['last_check_user_id'],
                    'cate_type' => 1,//审核消息
                    'type' => 1,//公告
                    'relation_id' => $id
                ];
            } elseif ($type == 2) {//任务
                $users = M('com_task')->where('id', $id)->find();
                if (!isset($users['status']) || $users['status'] != 0) {
                    return return_json(1, '状态不符合');
                }
                $data = [
                    'first_check_time' => time(),
                    'status' => 1,
                    'first_check_opinion' => $first_check_opinion
                ];
                $res = M('com_task')->where('id', $id)->update($data);
                if (empty($res)) {
                    return return_json(1, '审核失败');
                }
                //记录人
                $data_message[] = [
                    'title' => '您有任务记录已通过初审',
                    'user_id' => $users['record_user_id'],
                    'cate_type' => 2,//任务消息
                    'type' => 2,//任务
                    'relation_id' => $id
                ];
                //终审人
                $data_message[] = [
                    'title' => '您有一条公告记录需要您审核(终审)',
                    'user_id' => $users['last_check_user_id'],
                    'cate_type' => 1,//审核消息
                    'type' => 2,//任务
                    'relation_id' => $id
                ];
            } elseif ($type == 3) {//积分奖扣
                $users = M('com_integral_prize_buckle')->where('id', $id)->find();
                if (!isset($users['status']) || $users['status'] != 0) {
                    return return_json(1, '状态不符合');
                }
                $data = [
                    'first_check_time' => time(),
                    'status' => 1,
                    'first_check_opinion' => $first_check_opinion
                ];
                $res = M('com_integral_prize_buckle')->where('id', $id)->update($data);
                if (empty($res)) {
                    return return_json(1, '审核失败');
                }
                //记录人
                $data_message[] = [
                    'title' => '您有一条记录已通过初审',
                    'user_id' => $users['record_user_id'],
                    'cate_type' => 4,//积分奖扣消息
                    'type' => 3,//积分奖扣
                    'relation_id' => $id
                ];
                //终审人
                $data_message[] = [
                    'title' => '您有一条奖扣记录需要您审核(终审)',
                    'user_id' => $users['last_check_user_id'],
                    'cate_type' => 1,//审核消息
                    'type' => 3,//积分奖扣
                    'relation_id' => $id
                ];
            } elseif ($type == 4) {//请假
                $users = M('com_leave')->where('id', $id)->find();
                if (!isset($users['status']) || $users['status'] != 0) {
                    return return_json(1, '状态不符合');
                }
                $data = [
                    'first_check_time' => time(),
                    'status' => 1,
                    'first_check_desc' => $first_check_opinion
                ];
                $res = M('com_leave')->where('id', $id)->update($data);
                if (empty($res)) {
                    return return_json(1, '审核失败');
                }
                //记录人
                $data_message[] = [
                    'title' => '您有请假记录已通过初审',
                    'user_id' => $users['user_id'],
                    'cate_type' => 7,//请假消息
                    'type' => 4,//请假
                    'relation_id' => $id
                ];
                //终审人
                $data_message[] = [
                    'title' => '您有一条请假记录需要您审核(终审)',
                    'user_id' => $users['last_check_user_id'],
                    'cate_type' => 1,//审核消息
                    'type' => 4,//请假
                    'relation_id' => $id
                ];
            }
            Message::send_message_list($data_message);
            DB::commit();
            return return_json(0);
        } catch (\Exception $e) {
            DB::rollback();
            return return_json(1, $e->getMessage());
        }

    }
    //初审驳回
    //公告.任务.积分奖扣.请假
    public function first_check_reject()
    {
        $id = I('id', 0);
        $type = I('type', 1); //1公告  2任务 3积分奖扣 4请假
        $first_check_opinion = I('first_check_opinion', '');
        if (empty($id)) {
            return return_json(1, 'id不能为空');
        }
        DB::startTrans();
        try {
            //发送消息
            $data_message = [];
            if ($type == 1) {//公告
                $users = M('com_notice')->where('id', $id)->find();
                if (!isset($users['status']) || $users['status'] != 0) {
                    return return_json(1, '状态不符合');
                }
                $data = [
                    'first_check_time' => time(),
                    'status' => 4,//拟稿
                    'reject_type' => 1,
                    'check_status' => 2,//驳回
                    'first_check_opinion' => $first_check_opinion
                ];
                $res = M('com_notice')->where('id', $id)->update($data);
                if (empty($res)) {
                    return return_json(1, '审核失败');
                }
                //记录人
                $data_message[] = [
                    'title' => '您有公告记录被驳回',
                    'user_id' => $users['record_user_id'],
                    'cate_type' => 3,//公告消息
                    'type' => 1,//公告
                    'relation_id' => $id
                ];
            } elseif ($type == 2) {
                $users = M('com_task')->where('id', $id)->find();
                if (!isset($users['status']) || $users['status'] != 0) {
                    return return_json(1, '状态不符合');
                }
                $data = [
                    'first_check_time' => time(),
                    'status' => 5,//拟稿
                    'reject_type' => 1,
                    'check_status' => 2,//驳回
                    'first_check_opinion' => $first_check_opinion
                ];
                $res = M('com_task')->where('id', $id)->update($data);
                if (empty($res)) {
                    return return_json(1, '审核失败');
                }
                //记录人
                $data_message[] = [
                    'title' => '您有任务记录已驳回',
                    'user_id' => $users['record_user_id'],
                    'cate_type' => 2,//任务消息
                    'type' => 2,//任务
                    'relation_id' => $id
                ];
            } elseif ($type == 3) {
                $users = M('com_integral_prize_buckle')->where('id', $id)->find();
                if (!isset($users['status']) || $users['status'] != 0) {
                    return return_json(1, '状态不符合');
                }
                $data = [
                    'first_check_time' => time(),
                    'status' => 4,//拟稿
                    'check_status' => 2,//驳回
                    'reject_type' => 1,//初审驳回
                    'first_check_opinion' => $first_check_opinion
                ];
                $res = M('com_integral_prize_buckle')->where('id', $id)->update($data);
                if (empty($res)) {
                    return return_json(1, '审核失败');
                }
                //记录人
                $data_message[] = [
                    'title' => '您有一条记录被驳回',
                    'user_id' => $users['record_user_id'],
                    'cate_type' => 4,//积分奖扣消息
                    'type' => 3,//积分奖扣
                    'relation_id' => $id
                ];
            } elseif ($type == 4) {
                $users = M('com_leave')->where('id', $id)->find();
                if (!isset($users['status']) || $users['status'] != 0) {
                    return return_json(1, '状态不符合');
                }
                $data = [
                    'first_check_time' => time(),
                    'status' => 3,//拟稿
                    'check_status' => 2,//驳回
                    'reject_type' => 1,
                    'first_check_desc' => $first_check_opinion
                ];
                $res = M('com_leave')->where('id', $id)->update($data);
                if (empty($res)) {
                    return return_json(1, '审核失败');
                }
                //记录人
                $data_message[] = [
                    'title' => '您有请假记录被驳回',
                    'user_id' => $users['user_id'],
                    'cate_type' => 7,//请假消息
                    'type' => 4,//请假
                    'relation_id' => $id
                ];
            }
            Message::send_message_list($data_message);
            DB::commit();
            return return_json(0);
        } catch (\Exception $e) {
            DB::rollback();
            return return_json(1, $e->getMessage());
        }
    }
    //初审通过撤回
    //公告.任务.积分奖扣.请假
    public function first_check_recall()
    {
        $id = I('id', 0);
        $type = I('type', 1); //1公告  2任务 3积分奖扣 4请假
        if (empty($id)) {
            return return_json(1, 'id不能为空');
        }
        DB::startTrans();
        try {
            //发送消息
            $data_message = [];
            if ($type == 1) {//公告
                $users = M('com_notice')->where('id', $id)->find();
                if (!isset($users['status']) || $users['status'] != 1) {
                    return return_json(1, '状态不符合');
                }
                if($users['first_check_user_id'] == $users['record_user_id']){
                    $data = [
                        'status' => 4,//拟稿
                    ];
                }else{
                    $data = [
                        'status' => 0,//待初审
                    ];
                }
                $res = M('com_notice')->where('id', $id)->update($data);
                if (empty($res)) {
                    return return_json(1, '审核失败');
                }
                //记录人
                $data_message[] = [
                    'title' => '您有公告记录初审被撤回',
                    'user_id' => $users['record_user_id'],
                    'cate_type' => 3,//公告消息
                    'type' => 1,//公告
                    'relation_id' => $id
                ];
            } elseif ($type == 2) {
                $users = M('com_task')->where('id', $id)->find();
                if (!isset($users['status']) || $users['status'] != 1) {
                    return return_json(1, '状态不符合');
                }
                if($users['first_check_user_id'] == $users['record_user_id']){
                    $data = [
                        'status' => 5,//拟稿
                    ];
                }else{
                    $data = [
                        'status' => 0,//待初审
                    ];
                }
                $res = M('com_task')->where('id', $id)->update($data);
                if (empty($res)) {
                    return return_json(1, '审核失败');
                }
                //记录人
                $data_message[] = [
                    'title' => '您有任务记录初审被撤回',
                    'user_id' => $users['record_user_id'],
                    'cate_type' => 2,//任务消息
                    'type' => 2,//任务
                    'relation_id' => $id
                ];
            } elseif ($type == 3) {
                $users = M('com_integral_prize_buckle')->where('id', $id)->find();
                if (!isset($users['status']) || $users['status'] != 1) {
                    return return_json(1, '状态不符合');
                }
                if($users['first_check_user_id'] == $users['record_user_id']){
                    $data = [
                        'status' => 4,//拟稿
                        'check_status' => 1,//撤回
                    ];
                }else{
                    $data = [
                        'status' => 0,//待初审
                        'check_status' => 1,//撤回
                    ];
                }
                $res = M('com_integral_prize_buckle')->where('id', $id)->update($data);
                if (empty($res)) {
                    return return_json(1, '审核失败');
                }
                //记录人
                $data_message[] = [
                    'title' => '您有一条记录初审被撤回',
                    'user_id' => $users['record_user_id'],
                    'cate_type' => 4,//积分奖扣消息
                    'type' => 3,//积分奖扣
                    'relation_id' => $id
                ];
            } elseif ($type == 4) {
                $users = M('com_leave')->where('id', $id)->find();
                if (!isset($users['status']) || $users['status'] != 1) {
                    return return_json(1, '状态不符合');
                }
                if($users['first_check_user_id'] == $users['user_id']){
                    $data = [
                        'status' => 3,//拟稿
                    ];
                }else{
                    $data = [
                        'status' => 0,//待初审
                    ];
                }
                $res = M('com_leave')->where('id', $id)->update($data);
                if (empty($res)) {
                    return return_json(1, '审核失败');
                }
                //记录人
                $data_message[] = [
                    'title' => '您有请假记录初审被撤回',
                    'user_id' => $users['user_id'],
                    'cate_type' => 7,//请假消息
                    'type' => 4,//请假
                    'relation_id' => $id
                ];
            }
            Message::send_message_list($data_message);
            DB::commit();
            return return_json(0);
        } catch (\Exception $e) {
            DB::rollback();
            return return_json(1, $e->getMessage());
        }
    }
    //记录人撤回
    //公告.任务.积分奖扣.请假
    public function record_recall()
    {
        $id = I('id', 0);
        $type = I('type', 1); //1公告  2任务 3积分奖扣 4请假
        if (empty($id)) {
            return return_json(1, 'id不能为空');
        }
        //发送消息
        $data_message = [];
        if ($type == 1) {//公告
            $users = M('com_notice')->where('id', $id)->find();
            if (!isset($users['status']) || $users['status'] != 0) {
                return return_json(1, '状态不符合');
            }
            $data = [
                'status' => 4,//拟稿
                'check_status' => 1,//撤回
            ];
            $res = M('com_notice')->where('id', $id)->update($data);
            if (empty($res)) {
                return return_json(1, '撤回失败');
            }

        } elseif ($type == 2) {
            $users = M('com_task')->where('id', $id)->find();
            if (!isset($users['status']) || $users['status'] != 0) {
                return return_json(1, '状态不符合');
            }
            $data = [
                'status' => 5,//拟稿
                'check_status' => 1,//撤回
            ];
            $res = M('com_task')->where('id', $id)->update($data);
            if (empty($res)) {
                return return_json(1, '撤回失败');
            }
        } elseif ($type == 3) {
            $users = M('com_integral_prize_buckle')->where('id', $id)->find();
            if (!isset($users['status']) || $users['status'] != 0) {
                return return_json(1, '状态不符合');
            }
            $data = [
                'status' => 4,//拟稿
                'check_status' => 1,//撤回
            ];
            $res = M('com_integral_prize_buckle')->where('id', $id)->update($data);
            if (empty($res)) {
                return return_json(1, '撤回失败');
            }
        } elseif ($type == 4) {
            $users = M('com_leave')->where('id', $id)->find();
            if (!isset($users['status']) || $users['status'] != 0) {
                return return_json(1, '状态不符合');
            }
            $data = [
                'status' => 3,//拟稿
                'check_status' => 1,//撤回
            ];
            $res = M('com_leave')->where('id', $id)->update($data);
            if (empty($res)) {
                return return_json(1, '撤回失败');
            }
        }
        return return_json(0);
    }
    //终审通过
    //公告.任务.积分奖扣.请假
    public function last_check_pass()
    {
        $id = I('id', 0);
        $type = I('type', 1); //1公告  2任务 3积分奖扣 4请假
        $last_check_opinion = I('last_check_opinion', '');
        $first_integral = I('first_integral', 0);//积分奖扣 初审人奖分
        $record_integral = I('record_integral', 0);//积分奖扣 记录人送分值
        if (empty($id)) {
            return return_json(1, 'id不能为空');
        }
        DB::startTrans();
        try {
            //发送消息
            $data_message = [];
            if ($type == 1) {//公告
                $users = M('com_notice')->where('id', $id)->find();
                if (!isset($users['status']) || $users['status'] != 1) {
                    return return_json(1, '状态不符合');
                }
                $data = [
                    'last_check_time' => time(),
                    'status' => 2,
                    'last_check_opinion' => $last_check_opinion
                ];
                $res = M('com_notice')->where('id', $id)->update($data);
                if (empty($res)) {
                    return return_json(1, '审核失败');
                }
                //记录人奖分
                SendIntegralNew::send($id, 1);
                //记录人
                $data_message[] = [
                    'title' => '您有公告记录已通过终审',
                    'user_id' => $users['record_user_id'],
                    'cate_type' => 3,//公告消息
                    'type' => 1,//公告
                    'relation_id' => $id
                ];
                //初审人
                $data_message[] = [
                    'title' => '您有一条公告审核已通过终审',
                    'user_id' => $users['first_check_user_id'],
                    'cate_type' => 1,//审核消息
                    'type' => 1,//公告
                    'relation_id' => $id
                ];
                //参与人
                $list = M('com_notice_relation')->where('notice_id', $id)->select();
                foreach ($list as $key => $value) {
                    $data_message[] = [
                        'title' => '您有一条公告待阅读',
                        'user_id' => $value['user_id'],
                        'cate_type' => 3,//公告消息
                        'type' => 1,//公告
                        'relation_id' => $id
                    ];
                }
            } elseif ($type == 2) {
                $users = M('com_task')->where('id', $id)->find();
                if (!isset($users['status']) || $users['status'] != 1) {
                    return return_json(1, '状态不符合');
                }
                if($users['type'] == 1){
                    $data = [
                        'last_check_time' => time(),
                        'status' => 3,
                        'last_check_opinion' => $last_check_opinion
                    ];
                }else{
                    $data = [
                        'last_check_time' => time(),
                        'status' => 2,
                        'last_check_opinion' => $last_check_opinion
                    ];
                }

                $res = M('com_task')->where('id', $id)->update($data);
                if (empty($res)) {
                    return return_json(1, '审核失败');
                }
                //记录人
                $data_message[] = [
                    'title' => '您有任务记录已通过终审',
                    'user_id' => $users['record_user_id'],
                    'cate_type' => 2,//任务消息
                    'type' => 2,//任务
                    'relation_id' => $id
                ];
                //记录人加分
                SendIntegralNew::send($id, 2);
                //初审人
                $data_message[] = [
                    'title' => '您有一条任务审核已通过终审',
                    'user_id' => $users['first_check_user_id'],
                    'cate_type' => 1,//审核消息
                    'type' => 2,//任务
                    'relation_id' => $id
                ];
                //参与人
                $list = M('com_task_relation_take')->where('task_id', $id)->select();
                foreach ($list as $key => $value) {
                    $data_message[] = [
                        'title' => '您有一条参与的任务已通过终审',
                        'user_id' => $value['user_id'],
                        'cate_type' => 2,//任务消息
                        'type' => 2,//任务
                        'relation_id' => $id
                    ];
                }
                //负责人
                $data_message[] = [
                    'title' => '您有一条负责的任务已通过终审',
                    'user_id' => $users['principal_user_id'],
                    'cate_type' => 2,//任务消息
                    'type' => 2,//任务
                    'relation_id' => $id
                ];
                //悬赏任务 报名人
                if ($users['type'] == 2) {
                    $list_a = M('com_task_relation')->where('task_id', $id)->select();
                    foreach ($list_a as $key => $value) {
                        $data_message[] = [
                            'title' => '您有一条可以报名的任务已通过终审',
                            'user_id' => $value['user_id'],
                            'cate_type' => 2,//任务消息
                            'type' => 2,//任务
                            'relation_id' => $id
                        ];
                    }
                }
            } elseif ($type == 3) {
                $users = M('com_integral_prize_buckle')->where('id', $id)->find();
                if (!isset($users['status']) || $users['status'] != 1) {
                    return return_json(1, '状态不符合');
                }
                $data = [
                    'last_check_time' => time(),
                    'status' => 2,
                    'last_check_opinion' => $last_check_opinion
                ];
                $res = M('com_integral_prize_buckle')->where('id', $id)->update($data);
                if (empty($res)) {
                    return return_json(1, '审核失败');
                }
                //奖扣送分
                SendIntegralNew::send($id, 3, $first_integral, $record_integral);
                //记录人
                $data_message[] = [
                    'title' => '您有一条积分奖扣已通过终审',
                    'user_id' => $users['record_user_id'],
                    'cate_type' => 4,//积分奖扣消息
                    'type' => 3,//积分奖扣
                    'relation_id' => $id
                ];
                //初审人
                $data_message[] = [
                    'title' => '您有一条奖扣审核已通过终审',
                    'user_id' => $users['first_check_user_id'],
                    'cate_type' => 1,//积分奖扣消息
                    'type' => 3,//积分奖扣
                    'relation_id' => $id
                ];
                //抄送人
                if (!empty($users['copy_user_id'])) {
                    $data_message[] = [
                        'title' => '您有一条相关的奖扣已通过终审',
                        'user_id' => $users['copy_user_id'],
                        'cate_type' => 4,//积分奖扣消息
                        'type' => 3,//积分奖扣
                        'relation_id' => $id
                    ];
                }
                //参与人
                $list = M('com_integral_event_relation_users a')
                    ->join('com_integral_prize_buckle_relation_event b', 'a.event_id=b.id', 'left')
                    ->where('b.prize_buckle_id', $id)
                    ->field('a.user_id')
                    ->select();
                foreach ($list as $key => $value) {
                    $data_message[] = [
                        'title' => '您有一条参与的积分奖扣已通过终审',
                        'user_id' => $value['user_id'],
                        'cate_type' => 4,//积分奖扣消息
                        'type' => 3,//积分奖扣
                        'relation_id' => $id
                    ];
                }

            } elseif ($type == 4) {
                $users = M('com_leave')->where('id', $id)->find();
                if (!isset($users['status']) || $users['status'] != 1) {
                    return return_json(1, '状态不符合');
                }
                $data = [
                    'last_check_time' => time(),
                    'status' => 2,
                    'last_check_desc' => $last_check_opinion
                ];
                $res = M('com_leave')->where('id', $id)->update($data);
                if (empty($res)) {
                    return return_json(1, '审核失败');
                }
                SendIntegralNew::send($id, 4);
                //记录人
                $data_message[] = [
                    'title' => '您有请假记录已通过终审',
                    'user_id' => $users['user_id'],
                    'cate_type' => 7,//请假消息
                    'type' => 4,//请假
                    'relation_id' => $id
                ];
                //初审人
                $data_message[] = [
                    'title' => '您有一条请假审核已通过终审',
                    'user_id' => $users['first_check_user_id'],
                    'cate_type' => 1,//审核消息
                    'type' => 4,//请假
                    'relation_id' => $id
                ];
            }
            Message::send_message_list($data_message);
            DB::commit();
            return return_json(0);
        } catch (\Exception $e) {
            DB::rollback();
            return return_json(1, $e->getMessage());
        }
    }
    //终审驳回
    //公告.任务.积分奖扣.请假
    public function last_check_reject()
    {
        $id = I('id', 0);
        $type = I('type', 1); //1公告  2任务 3积分奖扣 4请假
        $last_check_opinion = I('last_check_opinion', '');
        $first_integral = I('first_integral', 0);//积分奖扣 初审人扣分
        $record_integral = I('record_integral', 0);//积分奖扣 记录人扣分
        if (empty($id)) {
            return return_json(1, 'id不能为空');
        }
        DB::startTrans();
        try {
            //发送消息
            $data_message = [];
            if ($type == 1) {//公告
                $users = M('com_notice')->where('id', $id)->find();
                if (!isset($users['status']) || $users['status'] != 1) {
                    return return_json(1, '状态不符合');
                }
                $data = [
                    'last_check_time' => time(),
                    'status' => 4,
                    'check_status' => 2,//驳回
                    'reject_type' => 2,//终审驳回
                    'last_check_opinion' => $last_check_opinion
                ];
                $res = M('com_notice')->where('id', $id)->update($data);
                if (empty($res)) {
                    return return_json(1, '驳回失败');
                }
                //记录人
                $data_message[] = [
                    'title' => '您有公告记录被驳回',
                    'user_id' => $users['record_user_id'],
                    'cate_type' => 3,//公告消息
                    'type' => 1,//公告
                    'relation_id' => $id
                ];
                //初审人
                $data_message[] = [
                    'title' => '您有一条公告审核被驳回',
                    'user_id' => $users['first_check_user_id'],
                    'cate_type' => 1,//审核消息
                    'type' => 1,//公告
                    'relation_id' => $id
                ];
            } elseif ($type == 2) {
                $users = M('com_task')->where('id', $id)->find();
                if (!isset($users['status']) || $users['status'] != 1) {
                    return return_json(1, '状态不符合');
                }
                $data = [
                    'last_check_time' => time(),
                    'status' => 5,
                    'check_status' => 2,//驳回
                    'reject_type' => 2,//终审驳回
                    'last_check_opinion' => $last_check_opinion
                ];
                $res = M('com_task')->where('id', $id)->update($data);
                if (empty($res)) {
                    return return_json(1, '驳回失败');
                }
                //记录人
                $data_message[] = [
                    'title' => '您有任务记录被驳回',
                    'user_id' => $users['record_user_id'],
                    'cate_type' => 2,//任务消息
                    'type' => 2,//任务
                    'relation_id' => $id
                ];
                //初审人
                $data_message[] = [
                    'title' => '您有一条任务审核被驳回',
                    'user_id' => $users['first_check_user_id'],
                    'cate_type' => 1,//审核消息
                    'type' => 2,//任务
                    'relation_id' => $id
                ];
            } elseif ($type == 3) {
                $users = M('com_integral_prize_buckle')->where('id', $id)->find();
                if (!isset($users['status']) || $users['status'] != 1) {
                    return return_json(1, '状态不符合');
                }
                $data = [
                    'last_check_time' => time(),
                    'status' => 4,
                    'check_status' => 2,
                    'reject_type' => 2,//终审驳回
                    'last_check_opinion' => $last_check_opinion
                ];
                $res = M('com_integral_prize_buckle')->where('id', $id)->update($data);
                if (empty($res)) {
                    return return_json(1, '驳回失败');
                }
                //驳回扣分
                //初审人扣分
                if ($first_integral != 0) {
                    $first_integral = -abs($first_integral);
                    $users['user_id'] = $users['first_check_user_id'];
                    $users['name'] = '驳回扣分';
                    SendIntegralNew::add_record_integral($users, $first_integral, 0, 34, true);
                }
                //记录人扣分
                if ($record_integral != 0) {
                    $record_integral = -abs($record_integral);
                    $users['user_id'] = $users['record_user_id'];
                    $users['name'] = '驳回扣分';
                    SendIntegralNew::add_record_integral($users, $record_integral, 0, 33, true);
                }
                //奖扣送分
                //SendIntegralNew::send($id, 3, $first_integral, $record_integral);
                //记录人
                $data_message[] = [
                    'title' => '您有一条积分奖扣被驳回',
                    'user_id' => $users['record_user_id'],
                    'cate_type' => 4,//积分奖扣消息
                    'type' => 3,//积分奖扣
                    'relation_id' => $id
                ];
                //初审人
                $data_message[] = [
                    'title' => '您有一条奖扣审核被驳回',
                    'user_id' => $users['first_check_user_id'],
                    'cate_type' => 1,//审核消息
                    'type' => 3,//积分奖扣
                    'relation_id' => $id
                ];
                //抄送人
                if (!empty($users['copy_user_id'])) {
                    $data_message[] = [
                        'title' => '您有一条相关的奖扣被驳回',
                        'user_id' => $users['copy_user_id'],
                        'cate_type' => 4,//积分奖扣消息
                        'type' => 3,//积分奖扣
                        'relation_id' => $id
                    ];
                }
            } elseif ($type == 4) {
                $users = M('com_leave')->where('id', $id)->find();
                if (!isset($users['status']) || $users['status'] != 1) {
                    return return_json(1, '状态不符合');
                }
                $data = [
                    'last_check_time' => time(),
                    'status' => 3,
                    'check_status' => 2,//驳回
                    'reject_type' => 2,//终审驳回
                    'last_check_desc' => $last_check_opinion
                ];
                $res = M('com_leave')->where('id', $id)->update($data);
                if (empty($res)) {
                    return return_json(1, '审核失败');
                }
                //SendIntegralNew::send($id, 4);
                //记录人
                $data_message[] = [
                    'title' => '您有请假记录被驳回',
                    'user_id' => $users['user_id'],
                    'cate_type' => 7,//请假消息
                    'type' => 4,//请假
                    'relation_id' => $id
                ];
                //初审人
                $data_message[] = [
                    'title' => '您有一条请假审核被驳回',
                    'user_id' => $users['first_check_user_id'],
                    'cate_type' => 1,//审核消息
                    'type' => 4,//请假
                    'relation_id' => $id
                ];
            }
            Message::send_message_list($data_message);
            DB::commit();
            return return_json(0);
        } catch (\Exception $e) {
            DB::rollback();
            return return_json(1, $e->getMessage());
        }
    }
    //积分奖扣
    //终审通过撤回
    public function last_check_recall()
    {
        $id = I('id', 0);
        if (empty($id)) {
            return return_json(1, 'id不能为空');
        }
        DB::startTrans();
        try {
            $users = M('com_integral_prize_buckle')->where('id', $id)->find();
            if (!isset($users['status']) || $users['status'] != 2) {
                return return_json(1, '状态不符合');
            }
            $data = [
                'status' => 1,
                'check_status' => 1,//撤回
            ];
            $res = M('com_integral_prize_buckle')->where('id', $id)->update($data);
            if (empty($res)) {
                return return_json(1, '撤回失败');
            }
            //原路撤回奖扣
            EventCheck::audit_withdraw($users);
            //记录人
            $data_message[] = [
                'title' => '您有一条积分奖扣终审撤回',
                'user_id' => $users['record_user_id'],
                'cate_type' => 4,//积分奖扣消息
                'type' => 3,//积分奖扣
                'relation_id' => $id
            ];
            //初审人
            $data_message[] = [
                'title' => '您有一条奖扣审核终审撤回',
                'user_id' => $users['first_check_user_id'],
                'cate_type' => 1,//审核消息
                'type' => 3,//积分奖扣
                'relation_id' => $id
            ];
            //抄送人
            if (!empty($users['copy_user_id'])) {
                $data_message[] = [
                    'title' => '您有一条相关的奖扣终审撤回',
                    'user_id' => $users['copy_user_id'],
                    'cate_type' => 4,//积分奖扣消息
                    'type' => 3,//积分奖扣
                    'relation_id' => $id
                ];
            }
            //参与人
            $list = M('com_integral_event_relation_users a')
                ->join('com_integral_prize_buckle_relation_event b', 'a.event_id=b.id', 'left')
                ->where('b.prize_buckle_id', $id)
                ->field('a.user_id')
                ->select();
            foreach ($list as $key => $value) {
                $data_message[] = [
                    'title' => '您有一条参与的积分奖扣终审撤回',
                    'user_id' => $value['user_id'],
                    'cate_type' => 4,//积分奖扣消息
                    'type' => 3,//积分奖扣
                    'relation_id' => $id
                ];
            }
            Message::send_message_list($data_message);
            DB::commit();
            return return_json(0);
        } catch (\Exception $e) {
            DB::rollback();
            return return_json(1, $e->getMessage());
        }
    }
    //催审
    //公告.任务.积分奖扣.请假
    public function push_check()
    {
        $id = I('id', 0);
        $type = I('type', 1); //1公告  2任务 3积分奖扣 4请假
        if (empty($id)) {
            return return_json(1, 'id不能为空');
        }
        DB::startTrans();
        try {
            //发送消息
            $data_message = [];
            if ($type == 1) {//公告
                $users = M('com_notice')->where('id', $id)->find();
                if ($users['status'] != 1 && $users['status'] != 0) {
                    return return_json(1, '状态不符合');
                }
                if($users['status'] == 1){
                    //终审人
                    $data_message[] = [
                        'title' => '您有一条公告记录需要您尽快审核(终审)',
                        'user_id' => $users['last_check_user_id'],
                        'cate_type' => 5,//催审消息
                        'type' => 1,//公告
                        'relation_id' => $id
                    ];
                }elseif ($users['status'] == 0){
                    //初审人
                    $data_message[] = [
                        'title' => '您有一条公告记录需要您尽快审核(初审)',
                        'user_id' => $users['first_check_user_id'],
                        'cate_type' => 5,//催审消息
                        'type' => 1,//公告
                        'relation_id' => $id
                    ];
                }

            } elseif ($type == 2) {
                $users = M('com_task')->where('id', $id)->find();
                if ($users['status'] != 1 && $users['status'] != 0) {
                    return return_json(1, '状态不符合');
                }
                if($users['status'] == 1){
                    //终审人
                    $data_message[] = [
                        'title' => '您有一条任务记录需要您尽快审核(终审)',
                        'user_id' => $users['last_check_user_id'],
                        'cate_type' => 5,//催审消息
                        'type' => 2,//任务
                        'relation_id' => $id
                    ];
                }elseif ($users['status'] == 0){
                    //初审人
                    $data_message[] = [
                        'title' => '您有一条任务记录需要您尽快审核(初审)',
                        'user_id' => $users['first_check_user_id'],
                        'cate_type' => 5,//催审消息
                        'type' => 2,//任务
                        'relation_id' => $id
                    ];
                }
            } elseif ($type == 3) {
                $users = M('com_integral_prize_buckle')->where('id', $id)->find();
                if ($users['status'] != 1 && $users['status'] != 0) {
                    return return_json(1, '状态不符合');
                }
                if($users['status'] == 1){
                    //终审人
                    $data_message[] = [
                        'title' => '您有一条奖扣记录需要您尽快审核(终审)',
                        'user_id' => $users['last_check_user_id'],
                        'cate_type' => 5,//催审消息
                        'type' => 3,//积分奖扣
                        'relation_id' => $id
                    ];
                }elseif ($users['status'] == 0){
                    //初审人
                    $data_message[] = [
                        'title' => '您有一条奖扣记录需要您尽快审核(初审)',
                        'user_id' => $users['first_check_user_id'],
                        'cate_type' => 5,//催审消息
                        'type' => 3,//积分奖扣
                        'relation_id' => $id
                    ];
                }
            } elseif ($type == 4) {
                $users = M('com_leave')->where('id', $id)->find();
                if ($users['status'] != 1 && $users['status'] != 0) {
                    return return_json(1, '状态不符合');
                }
                if($users['status'] == 1){
                    //终审人
                    $data_message[] = [
                        'title' => '您有一条请假记录需要您尽快审核(终审)',
                        'user_id' => $users['last_check_user_id'],
                        'cate_type' => 5,//催审消息
                        'type' => 4,//请假
                        'relation_id' => $id
                    ];
                }elseif ($users['status'] == 0){
                    //初审人
                    $data_message[] = [
                        'title' => '您有一条请假记录需要您尽快审核(初审)',
                        'user_id' => $users['first_check_user_id'],
                        'cate_type' => 5,//催审消息
                        'type' => 4,//请假
                        'relation_id' => $id
                    ];
                }
            }
            Message::send_message_list($data_message);
            DB::commit();
            return return_json(0);
        } catch (\Exception $e) {
            DB::rollback();
            return return_json(1, $e->getMessage());
        }
    }
    //记录人删除
    //公告.任务.积分奖扣.请假
    public function delete()
    {
        $id = I('id', 0);
        $type = I('type', 1); //1公告  2任务 3积分奖扣 4请假
        if (empty($id)) {
            return return_json(1, 'id不能为空');
        }
        DB::startTrans();
        try {
            if ($type == 1) {//公告
                //状态4
                $status = M('com_notice')->where('id',$id)->value('status');
                if($status != 4){
                    return return_json(1,'该状态不能删除');
                }
                M('com_notice_relation')->where('notice_id',$id)->delete();
                M('com_notice')->where('id',$id)->delete();
            }elseif ($type == 2){//任务
                //状态
                $status = M('com_task')->where('id',$id)->value('status');
                if($status != 5){
                    return return_json(1,'该状态不能删除');
                }
                M('com_task_relation_take')->where('task_id',$id)->delete();
                M('com_task_relation')->where('task_id',$id)->delete();
                M('com_task')->where('id',$id)->delete();
            }elseif ($type == 3){//积分奖扣
                //状态
                $status = M('com_integral_prize_buckle')->where('id',$id)->value('status');
                if($status != 4){
                    return return_json(1,'该状态不能删除');
                }
                $ids = M('com_integral_prize_buckle_relation_event')->where('prize_buckle_id',$id)->column('id');
                M('com_integral_event_relation_users')->where('event_id','in',$ids)->delete();
                M('com_integral_prize_buckle_relation_event')->where('prize_buckle_id',$id)->delete();
                M('com_integral_prize_buckle')->where('id',$id)->delete();
            }elseif ($type == 4){//请假
                $status = M('com_leave')->where('id',$id)->value('status');
                if($status != 3){
                    return return_json(1,'该状态不能删除');
                }
                M('com_leave')->where('id',$id)->delete();
            }
            DB::commit();
            return return_json(0);
        } catch (\Exception $e) {
            DB::rollback();
            return return_json(1, $e->getMessage());
        }
    }
    //终审批量审核
    //终审通过
    //公告.任务.积分奖扣.请假
    public function last_check_pass_batch()
    {
        $ids = I('ids', '');
        $type = I('type', 1); //1公告  2任务 3积分奖扣 4请假
        $last_check_opinion = I('last_check_opinion', '');
        $first_integral = I('first_integral', 0);//积分奖扣 初审人奖分
        $record_integral = I('record_integral', 0);//积分奖扣 记录人送分值
        if (empty($ids)) {
            return return_json(1, 'id不能为空');
        }
        $ids = str_replace('\\','',htmlspecialchars_decode($ids));
        $ids = json_decode($ids,true);
        DB::startTrans();
        try {
            //发送消息
            $data_message = [];
            if ($type == 1) {//公告
                foreach ($ids as $id) {
                    $users = M('com_notice')->where('id', $id)->find();
                    if (!isset($users['status']) || $users['status'] != 1) {
                        return return_json(1, '状态不符合');
                    }
                    $data = [
                        'last_check_time' => time(),
                        'status' => 2,
                        'last_check_opinion' => $last_check_opinion
                    ];
                    $res = M('com_notice')->where('id', $id)->update($data);
                    if (empty($res)) {
                        return return_json(1, '审核失败');
                    }
                    //记录人奖分
                    SendIntegralNew::send($id, 1);
                    //记录人
                    $data_message[] = [
                        'title' => '您有公告记录已通过终审',
                        'user_id' => $users['record_user_id'],
                        'cate_type' => 3,//公告消息
                        'type' => 1,//公告
                        'relation_id' => $id
                    ];
                    //初审人
                    $data_message[] = [
                        'title' => '您有一条公告审核已通过终审',
                        'user_id' => $users['first_check_user_id'],
                        'cate_type' => 1,//审核消息
                        'type' => 1,//公告
                        'relation_id' => $id
                    ];
                    //参与人
                    $list = M('com_notice_relation')->where('notice_id', $id)->select();
                    foreach ($list as $key => $value) {
                        $data_message[] = [
                            'title' => '您有一条公告待阅读',
                            'user_id' => $value['user_id'],
                            'cate_type' => 3,//公告消息
                            'type' => 1,//公告
                            'relation_id' => $id
                        ];
                    }
                }
            } elseif ($type == 2) {
                foreach ($ids as $id) {
                    $users = M('com_task')->where('id', $id)->find();
                    if (!isset($users['status']) || $users['status'] != 1) {
                        return return_json(1, '状态不符合');
                    }
                    if($users['type'] == 1){
                        $data = [
                            'last_check_time' => time(),
                            'status' => 3,
                            'last_check_opinion' => $last_check_opinion
                        ];
                    }else{
                        $data = [
                            'last_check_time' => time(),
                            'status' => 2,
                            'last_check_opinion' => $last_check_opinion
                        ];
                    }

                    $res = M('com_task')->where('id', $id)->update($data);
                    if (empty($res)) {
                        return return_json(1, '审核失败');
                    }
                    //记录人
                    $data_message[] = [
                        'title' => '您有任务记录已通过终审',
                        'user_id' => $users['record_user_id'],
                        'cate_type' => 2,//任务消息
                        'type' => 2,//任务
                        'relation_id' => $id
                    ];
                    //记录人加分
                    SendIntegralNew::send($id, 2);
                    //初审人
                    $data_message[] = [
                        'title' => '您有一条任务审核已通过终审',
                        'user_id' => $users['first_check_user_id'],
                        'cate_type' => 1,//审核消息
                        'type' => 2,//任务
                        'relation_id' => $id
                    ];
                    //参与人
                    $list = M('com_task_relation_take')->where('task_id', $id)->select();
                    foreach ($list as $key => $value) {
                        $data_message[] = [
                            'title' => '您有一条参与的任务已通过终审',
                            'user_id' => $value['user_id'],
                            'cate_type' => 2,//任务消息
                            'type' => 2,//任务
                            'relation_id' => $id
                        ];
                    }
                    //负责人
                    $data_message[] = [
                        'title' => '您有一条负责的任务已通过终审',
                        'user_id' => $users['principal_user_id'],
                        'cate_type' => 2,//任务消息
                        'type' => 2,//任务
                        'relation_id' => $id
                    ];
                    //悬赏任务 报名人
                    if ($users['type'] == 2) {
                        $list_a = M('com_task_relation')->where('task_id', $id)->select();
                        foreach ($list_a as $key => $value) {
                            $data_message[] = [
                                'title' => '您有一条可以报名的任务已通过终审',
                                'user_id' => $value['user_id'],
                                'cate_type' => 2,//任务消息
                                'type' => 2,//任务
                                'relation_id' => $id
                            ];
                        }
                    }
                }
            } elseif ($type == 3) {
                foreach ($ids as $id) {
                    $users = M('com_integral_prize_buckle')->where('id', $id)->find();
                    if (!isset($users['status']) || $users['status'] != 1) {
                        return return_json(1, '状态不符合');
                    }
                    $data = [
                        'last_check_time' => time(),
                        'status' => 2,
                        'last_check_opinion' => $last_check_opinion
                    ];
                    $res = M('com_integral_prize_buckle')->where('id', $id)->update($data);
                    if (empty($res)) {
                        return return_json(1, '审核失败');
                    }
                    //奖扣送分
                    SendIntegralNew::send($id, 3, $first_integral, $record_integral);
                    //记录人
                    $data_message[] = [
                        'title' => '您有一条积分奖扣已通过终审',
                        'user_id' => $users['record_user_id'],
                        'cate_type' => 4,//积分奖扣消息
                        'type' => 3,//积分奖扣
                        'relation_id' => $id
                    ];
                    //初审人
                    $data_message[] = [
                        'title' => '您有一条奖扣审核已通过终审',
                        'user_id' => $users['first_check_user_id'],
                        'cate_type' => 1,//积分奖扣消息
                        'type' => 3,//积分奖扣
                        'relation_id' => $id
                    ];
                    //抄送人
                    if (!empty($users['copy_user_id'])) {
                        $data_message[] = [
                            'title' => '您有一条相关的奖扣已通过终审',
                            'user_id' => $users['copy_user_id'],
                            'cate_type' => 4,//积分奖扣消息
                            'type' => 3,//积分奖扣
                            'relation_id' => $id
                        ];
                    }
                    //参与人
                    $list = M('com_integral_event_relation_users a')
                        ->join('com_integral_prize_buckle_relation_event b', 'a.event_id=b.id', 'left')
                        ->where('b.prize_buckle_id', $id)
                        ->field('a.user_id')
                        ->select();
                    foreach ($list as $key => $value) {
                        $data_message[] = [
                            'title' => '您有一条参与的积分奖扣已通过终审',
                            'user_id' => $value['user_id'],
                            'cate_type' => 4,//积分奖扣消息
                            'type' => 3,//积分奖扣
                            'relation_id' => $id
                        ];
                    }
                }
            } elseif ($type == 4) {
                foreach ($ids as $id) {
                    $users = M('com_leave')->where('id', $id)->find();
                    if (!isset($users['status']) || $users['status'] != 1) {
                        return return_json(1, '状态不符合');
                    }
                    $data = [
                        'last_check_time' => time(),
                        'status' => 2,
                        'last_check_desc' => $last_check_opinion
                    ];
                    $res = M('com_leave')->where('id', $id)->update($data);
                    if (empty($res)) {
                        return return_json(1, '审核失败');
                    }
                    SendIntegralNew::send($id, 4);
                    //记录人
                    $data_message[] = [
                        'title' => '您有请假记录已通过终审',
                        'user_id' => $users['user_id'],
                        'cate_type' => 7,//请假消息
                        'type' => 4,//请假
                        'relation_id' => $id
                    ];
                    //初审人
                    $data_message[] = [
                        'title' => '您有一条请假审核已通过终审',
                        'user_id' => $users['first_check_user_id'],
                        'cate_type' => 1,//审核消息
                        'type' => 4,//请假
                        'relation_id' => $id
                    ];
                }

            }
            Message::send_message_list($data_message);
            DB::commit();
            return return_json(0);
        } catch (\Exception $e) {
            DB::rollback();
            return return_json(1, $e->getMessage());
        }
    }
    //拟稿提交
    //公告.任务.积分奖扣.请假
    public function draft_submit()
    {
        $id = I('id', 0);
        $type = I('type', 1); //1公告  2任务 3积分奖扣 4请假
        if (empty($id)) {
            return return_json(1, 'id不能为空');
        }
        DB::startTrans();
        try {
            //发送消息
            $data_message = [];
            if ($type == 1) {//公告
                $users = M('com_notice')->where('id', $id)->find();
                if (!isset($users['status']) || $users['status'] != 4) {
                    return return_json(1, '状态不符合');
                }
                $data = [
                    'status' => 0,//待初审
                ];
                $res = M('com_notice')->where('id', $id)->update($data);
                if (empty($res)) {
                    return return_json(1, '审核失败');
                }
                //记录人
                $data_message[] = [
                    'title' => '您有公告记录提交审核',
                    'user_id' => $users['record_user_id'],
                    'cate_type' => 3,//公告消息
                    'type' => 1,//公告
                    'relation_id' => $id
                ];
                //初审人
                $data_message[] = [
                    'title' => '您有公告记录待审核(初审)',
                    'user_id' => $users['first_check_user_id'],
                    'cate_type' => 1,//审核消息
                    'type' => 1,//公告
                    'relation_id' => $id
                ];
            } elseif ($type == 2) {
                $users = M('com_task')->where('id', $id)->find();
                if (!isset($users['status']) || $users['status'] != 5) {
                    return return_json(1, '状态不符合');
                }
                $data = [
                    'status' => 0,//待初审
                ];
                $res = M('com_task')->where('id', $id)->update($data);
                if (empty($res)) {
                    return return_json(1, '审核失败');
                }
                //记录人
                $data_message[] = [
                    'title' => '您有任务记录提交审核',
                    'user_id' => $users['record_user_id'],
                    'cate_type' => 2,//任务消息
                    'type' => 2,//任务
                    'relation_id' => $id
                ];
                //初审人
                $data_message[] = [
                    'title' => '您有任务记录待审核(初审)',
                    'user_id' => $users['first_check_user_id'],
                    'cate_type' => 1,//审核消息
                    'type' => 2,//
                    'relation_id' => $id
                ];
            } elseif ($type == 3) {
                $users = M('com_integral_prize_buckle')->where('id', $id)->find();
                if (!isset($users['status']) || $users['status'] != 4) {
                    return return_json(1, '状态不符合');
                }
                $data = [
                    'status' => 0,//待初审
                    'check_status' => 1,//撤回
                ];
                $res = M('com_integral_prize_buckle')->where('id', $id)->update($data);
                if (empty($res)) {
                    return return_json(1, '审核失败');
                }
                //记录人
                $data_message[] = [
                    'title' => '您有一条积分奖扣记录提交审核',
                    'user_id' => $users['record_user_id'],
                    'cate_type' => 4,//积分奖扣消息
                    'type' => 3,//积分奖扣
                    'relation_id' => $id
                ];
                //初审人
                $data_message[] = [
                    'title' => '您有一条积分奖扣待审核(初审)',
                    'user_id' => $users['first_check_user_id'],
                    'cate_type' => 1,//审核消息
                    'type' => 3,//
                    'relation_id' => $id
                ];
            } elseif ($type == 4) {
                $users = M('com_leave')->where('id', $id)->find();
                if (!isset($users['status']) || $users['status'] != 3) {
                    return return_json(1, '状态不符合');
                }
                $data = [
                    'status' => 0,//待初审
                    'check_status'=>0
                ];
                $res = M('com_leave')->where('id', $id)->update($data);
                if (empty($res)) {
                    return return_json(1, '审核失败');
                }
                //记录人
                $data_message[] = [
                    'title' => '您有请假记录提交审核',
                    'user_id' => $users['user_id'],
                    'cate_type' => 7,//请假消息
                    'type' => 4,//请假
                    'relation_id' => $id
                ];
                //初审人
                $data_message[] = [
                    'title' => '您有请假记录待审核(初审)',
                    'user_id' => $users['first_check_user_id'],
                    'cate_type' => 1,//审核消息
                    'type' => 4,//
                    'relation_id' => $id
                ];
            }
            Message::send_message_list($data_message);
            DB::commit();
            return return_json(0);
        } catch (\Exception $e) {
            DB::rollback();
            return return_json(1, $e->getMessage());
        }
    }
    //积分奖扣待终审 终审人修改用户奖票和积分
    public function last_update_user(){

        $event_id = I('event_id',0);//事件id
        $user_data = I('user_data','');
        if(empty($user_data)){
            return return_json(1,'用户数据不能为空');
        }
        if(empty($event_id)){
            return return_json(1,'事件id不能为空');
        }
        $user_data = json_decode(htmlspecialchars_decode($user_data),true);
        DB::startTrans();
        try{
            foreach ($user_data as $key=>$value){
                $user_id = $value['user_id'];//用户id
                $integral_a = $value['integral_a'];//a分
                $integral_b = $value['integral_b']; //b分
                $is_lottery_ticket = $value['is_lottery_ticket']; //是否奖票 0否 1是
                $where = [];
                $where['user_id'] = $user_id;
                $where['event_id'] = $event_id;
                $data = [
                    'integral_a'=>$integral_a,
                    'integral_b'=>$integral_b,
                    'is_lottery_ticket'=>$is_lottery_ticket,
                ];
                M('com_integral_event_relation_users')->where($where)->update($data);
            }
            DB::commit();
            return return_json(0);
        }catch (\Exception $e){
            DB::rollback();
            return return_json(1,$e->getMessage());
        }
    }

}
